const express = require('express')
import { token } from '../modules/authorization'
const router = express.Router()

/* 测试设备环境 */
router.get('/', (req, res, next) => {
  res.render('index.ejs', { title: '测试设备环境' })
})
/* 测试网站相关 */
router.get('/test', (req, res, next) => {
  res.render('index1.ejs', { title: '测试网站相关' })
})

/* 首页 */
router.get('/api/user', (req, res, next) => {
  console.log('测试:', req.query)
  const data = {
    userId: 1,
    username: 'admin',
    token:
      'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwODgzOTUxOTk1NmI5NTBiMGI2YmE5NiIsInVzZXJuYW1lIjoiYWRtaW4iLCJwYXNzd29yZCI6IiQyYiQxMCQzSGR5c2FDWUswU3pmOTMuNTh2L2IuSUlsRU5INjZRMTRDbzl0NndFVEswYy9TQ2k5UFZhMiIsImlhdCI6MTYyODE1NzU2MiwiZXhwIjoxNjI4MjQzOTYyfQ.xhz9SPCRbQ6iuVRhJBbLqW418-VK1fRzaY-50QM6oqs',
  }
  res.sendResult(200, '操作成功', data)
})
router.post('/api/user', (req, res, next) => {
  console.log('测试:', req.body)
  const data = {
    userId: 1,
    username: 'admin',
    token:
      'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwODgzOTUxOTk1NmI5NTBiMGI2YmE5NiIsInVzZXJuYW1lIjoiYWRtaW4iLCJwYXNzd29yZCI6IiQyYiQxMCQzSGR5c2FDWUswU3pmOTMuNTh2L2IuSUlsRU5INjZRMTRDbzl0NndFVEswYy9TQ2k5UFZhMiIsImlhdCI6MTYyODE1NzU2MiwiZXhwIjoxNjI4MjQzOTYyfQ.xhz9SPCRbQ6iuVRhJBbLqW418-VK1fRzaY-50QM6oqs',
  }
  res.sendResult(200, '操作成功', data)
})

router.post('/api/insert', (req, res, next) => {
  console.log('测试:', req.body)
  const data = req.body
  res.sendResult(200, '操作成功', data)
})

module.exports = router
